/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 * \file     OsIf.c                                                                                     *
 * \brief    Semidrive os abstract layer                                                                *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2023/08/26     <td>1.0.0                                                                     *
 * </table>                                                                                             *
 *******************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif

#include "OsIf.h"
#ifdef CFG_USER_MODE_CASE
#include "Compiler.h"
#include "switch_mode.h"
#endif /** #ifdef CFG_USER_MODE_CASE */

#if defined(CFG_NOT_USED_AUTOSAR_OS)
/* In order to avoid data abort caused by the probability of bus error due to
    the misalignment of byte loading when XIP is not open when the cache is not
    open. */
/*================================================================================================*/
/**
* @brief OsIf_GetCoreID
* @details Function used to get the ID of the currently executing thread
*/
/*================================================================================================*/
#define OSIF_START_SEC_CODE
#include "OsIf_MemMap.h"

uint8 OsIf_GetCoreID(void)
{
    uint8 cpuId = 0;
#ifdef CFG_USER_MODE_CASE
    OS_GET_CORE_ID();
#else
    cpuId = OsIf_GetCpuId();
#endif /** #ifdef CFG_USER_MODE_CASE */
#if (CPU_MAX_CORE_NUMBER > 1U)
    if (cpuId > (CPU_MAX_CORE_NUMBER - 0x01U))
    {
        cpuId = (CPU_MAX_CORE_NUMBER- 0x01U);
    }
#endif /** #if (CPU_MAX_CORE_NUMBER > 1U) */

    return cpuId;
}

#define OSIF_STOP_SEC_CODE
#include "OsIf_MemMap.h"

#endif /** #if defined(CFG_NOT_USED_AUTOSAR_OS) */

#ifdef __cplusplus
}
#endif

/* End of file */
